<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>直接WebSocket测试</title>
</head>
<body>
    <h1>最简单的WebSocket测试</h1>
    <p>打开浏览器控制台查看详细信息</p>
    
    <button onclick="testWS()">测试WebSocket</button>
    <div id="status"></div>
    
    <script>
        function testWS() {
            const statusDiv = document.getElementById('status');
            statusDiv.innerHTML = "正在连接...";
            
            try {
                // 创建WebSocket连接
                const ws = new WebSocket("ws://localhost:8080/wsraw");
                
                ws.onopen = function(event) {
                    console.log("WebSocket连接已打开", event);
                    statusDiv.innerHTML = "连接成功！";
                    
                    // 发送一个测试消息
                    const testMsg = {
                        action: "test",
                        customerId: "test001",
                        timestamp: new Date().getTime()
                    };
                    ws.send(JSON.stringify(testMsg));
                    console.log("已发送测试消息");
                };
                
                ws.onmessage = function(event) {
                    console.log("收到消息:", event.data);
                    statusDiv.innerHTML += "<br>收到: " + event.data;
                };
                
                ws.onclose = function(event) {
                    console.log("连接已关闭", event);
                    statusDiv.innerHTML += "<br>连接已关闭 (代码: " + event.code + ")";
                    
                    if (event.code === 1006) {
                        statusDiv.innerHTML += "<br><strong>错误:</strong> 异常关闭 (代码1006) - 可能是服务器拒绝连接或未运行";
                    }
                };
                
                ws.onerror = function(error) {
                    console.error("WebSocket错误", error);
                    statusDiv.innerHTML += "<br><strong>错误:</strong> 连接出错";
                };
            } catch (e) {
                console.error("创建WebSocket失败", e);
                statusDiv.innerHTML = "创建WebSocket失败: " + e.message;
            }
        }
    </script>
</body>
</html> 